<template>
	<view class="box">
		<uNavbar title="市场订单" bgColor="#262241"></uNavbar>
		<view class="tab-nav">
			<view class="tab-list-item" v-for="(item,index) in toggleList" :key="item.id"
				@click="clickToggleHandle(item,index)">
				<view :class="{ active: indexs==index}" class="text">{{ item.label }}</view>
			</view>
		</view>
		<!--我接收的 -->
		<view style="margin-top: 100rpx;">
			<view class="main_from" v-if="selval=='买方'" v-for="item in orderlist" :key="item.id">
				<view class="main_from_top" @click="godetail(item.id,item.status)">
					<image :src="item.goods.goods_image" mode="aspectFill"></image>
					<view class="main_from_top_one">
						<view class="name">
							{{item.goods.goods_name}}
						</view>
						<view class="time">
							{{item.status_desc}}
						</view>
					</view>
					<view class="main_from_top_two">
						<view class="text">
							{{item.goods.shop_brand.name}}
						</view>
						<view class="num">
							×{{item.number}}
						</view>
					</view>
					<view class="main_from_top_three">
						<!-- 						<view class="tag_wrap">
							<view class="tag">
								编号
							</view>
							<view class="tag_num">
								200/1000
							</view>
						</view> -->
						<view class="price">
							<image v-if="item.pay_type==3" src="../../static/icon/money.png" mode=""></image>
							<image v-if="item.pay_type==4" src="../../static/icon/i_ys.png" mode=""></image>
							{{item.price}}
						</view>
					</view>
				</view>
				<view class="main_from_bottom" @click="godetail(item.id,item.status)">
					<view class="main_from_bottom_text">
						{{item.status==1?"查看详情":" "}}
					</view>
					<view class="btn_canel" style="right: 150rpx;" v-show="item.status==0" @click="itemid=item.id,tipShow2=true">
						取消订单
					</view>
					<!-- 		<view class="btn_canel" v-show="item.status==1">
						转赠
					</view> -->
					<view class="btn" v-show="item.status==0" @click="gounpaid(item.id,item.countDown)">
						去付款
					</view>
					<!-- 		<view class="btn" v-show="item.status==1" >
						挂卖
					</view> -->
				</view>
			</view>
			<view class="main_from" v-if="selval=='售卖方'" v-for="item in orderlist2" :key="item.id">
				<view class="main_from_top" @click="godetail2(item.id,item.status)">
					<image :src="item.good.goods_image" mode="aspectFill"></image>
					<view class="main_from_top_one">
						<view class="name">
							{{item.goods_name}}
						</view>
						<view class="time">
							{{item.status_desc}}
						</view>
						<!-- 	<view class="main_from_top_one_text" style="color: #FF2CDF;" v-show="selval=='售卖方'">
							买家待支付
						</view> -->
						<!-- 		<view class="main_from_top_one_text" v-show="selval=='已购买'">
							已购买
						</view> -->
					</view>
					<view class="main_from_top_two">
						<view class="text">
							{{item.good.shop_brand.name}}
						</view>
						<view class="num">
							×1
						</view>
					</view>
					<view class="main_from_top_three">
						<view class="tag_wrap">
							<view class="tag">
								编号
							</view>
							<view class="tag_num">
								{{item.goods_number}}/{{item.good.circulation}}
							</view>
						</view>
						<view class="price">
							<image src="../../static/icon/money.png" mode=""></image>{{item.price}}
						</view>
					</view>

				</view>
				<view class="main_from_bottom">
					<view class="main_from_bottom_text" v-if="item.status==2"  @click="godetail2(item.id,item.status)">
						查看详情
					</view>
					<view class="btn_canel" v-if="item.status==0" @click="itemid=item.id,tipShow=true">
						取消
					</view>
				</view>
			</view>
		</view>
		<u-popup :show="tipShow" mode="center" @close="tipShow = false" closeable bgColor="transparent">
			<view class="prompt flex_ZC">
				<text class="f36">提示</text>
				<text class="prompt_tit">确定要取消订单吗</text>

				<view class="prompt_ntm" @click="canel1()">
					<text>确定</text>
				</view>
				<view class="empty"></view>
			</view>
		</u-popup>
		<u-popup :show="tipShow2" mode="center" @close="tipShow2 = false" closeable bgColor="transparent">
			<view class="prompt flex_ZC">
				<text class="f36">提示</text>
				<text class="prompt_tit">确定要取消订单吗</text>

				<view class="prompt_ntm" @click="canelorder()">
					<text>确定</text>
				</view>
				<view class="empty"></view>
			</view>
		</u-popup>
		<noDatas v-if="selval=='买方'" :xxxList="orderlist" :status="status"></noDatas>
		<noDatas v-if="selval=='售卖方'" :xxxList="orderlist2" :status="status2"></noDatas>
	</view>

</template>

<script>
	import {
		rent_orders,
		canel,
		rentorder,
		cancleRent
	} from "../../api/order.js"
	export default {
		data() {
			return {
				toggleList: [{
						label: '买方',
						// select: true
					}, {
						label: '售卖方',
						// select: false
					}

				],
				selval: "买方",
				status: "已购买",
				status2: "未购买",
				orderlist: [],
				orderlist2: [],
				page: 1,
				size: 10,
				status: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				page2: 1,
				size2: 10,
				status2: 'loadmore', //加载前值为loadmore，加载中为loading，没有数据为nomore
				tipShow: false,
				tipShow2: false,
				itemid: "",
				indexs: 0,
			}
		},
		onLoad(options) {
			if (options.id == 2) {
				this.indexs = 1
				this.selval = "售卖方"
				console.log(this.selval)
				this.getlist2()
			}
			if (options.id == 1) {
				this.indexs = 0
				this.selval = "买方"
				console.log(this.selval)
				this.getlist()
			}
			this.getlist()
		},
		methods: {
			canelorder() {
				canel({
					id: this.itemid
				}).then(res => {
					if (res.code == 1) {
						this.tipShow2 = false,
							this.getlist()
					}
					console.log(res, "取消订单")
				})
			},
			canel1() {
				cancleRent({
					id: this.itemid
				}).then(res => {
					if (res.code == 1) {
						this.tipShow = false
						this.getlist2()
					}
					uni.$u.toast(res.msg)
				})
			},
			getlist() {
				rent_orders({
					page: this.page
				}).then(res => {
					if (res.code == 1) {
						let list = res.data.data;
						this.orderlist = this.page == 1 ? list : this.orderlist.concat(list);
						console.log(this.orderlist);
						if (list.length < this.size) this.status = 'nomore';
						else this.status = 'loading';
					}
				})
			},
			getlist2() {
				rentorder({
					page: this.page2
				}).then(res => {
					if (res.code == 1) {
						let list = res.data.data;
						this.orderlist2 = this.page2 == 1 ? list : this.orderlist2.concat(list);
						console.log(this.orderlist2);
						if (list.length < this.size2) this.status2 = 'nomore';
						else this.status2 = 'loading';
					}
					console.log(res)
				})
			},
			clickToggleHandle(ele, index) {
				this.indexs = index
				this.toggleList.forEach(item => item.select = false)
				this.currLabel = ele.label
				ele.select = true
				console.log(ele)
				this.selval = ele.label
				if (this.selval == "买方") {
					this.getlist()
				}
				if (this.selval == "售卖方") {
					this.getlist2()
				}
			},
			gounpaid(id) {
				uni.navigateTo({
					url: `/pagesMy/brandCenter/paymentCenter?productType=2&order_id=${id}`
				})
			},
			godetail(id, status) {
				console.log(status)
				if (status == 1 ) {
					uni.navigateTo({
						url: `/pagesMy/marketorder/marketorderdetail?id=${id}`
					})
				}

			},
			godetail2(id, status) {
				console.log(status)
				if (status == 2) {
					uni.navigateTo({
						url: `/pagesMy/marketorder/marketdetail?id=${id}`
					})
				}
			},
			gopaid() {
				if (this.selval == "已购买") {
					uni.navigateTo({
						url: "/pagesMy/myorder/paid"
					})
				} else {
					uni.navigateTo({
						url: "/pagesMy/myorder/unpaid"
					})
				}

			}

		},
		onReachBottom() {
			if (this.selval == "买方") {
				if (this.status != 'nomore') {
					this.page = this.page + 1
					this.getlist()
				}
			} else {
				if (this.status2 != 'nomore') {
					this.page2 = this.page2 + 1
					this.getlist2()
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.box {
		width: 750rpx;
		height: 100vh;
		background-color: #262241;
		position: relative;
	}

	.tab-nav {
		width: 750rpx;
		height: 100rpx;
		background-color: #262241;
		// margin-left: 20rpx;
		display: flex;
		align-items: center;
		position: fixed;
		z-index: 999;

		.tab-list-item {
			position: relative;
			width: 350rpx;

			.text {
				display: flex;
				justify-content: center;
				align-items: center;
				margin-left: 50rpx;
				padding: 20rpx;
				height: 52rpx;
				opacity: 1;
				font-weight: 400;
				text-align: center;
				font-size: 32rpx;
				color: #A6A5AF;
			}

			.active {
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}

	.main_from {
		width: 690rpx;
		height: 330rpx;
		background: #3C2F65;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 0 auto;
		margin-bottom: 30rpx;

		.main_from_top {
			margin: 0 auto;
			width: 630rpx;
			height: 220rpx;
			border-bottom: 2rpx solid rgba(216, 216, 216, 0.1);
			position: relative;

			>image {
				width: 154rpx;
				height: 154rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin-top: 30rpx;
			}

			.main_from_top_one {
				width: 420rpx;
				position: absolute;
				top: 36rpx;
				left: 192rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.name {
					width: 220rpx;
					height: 52rpx;
					font-weight: 400;
					font-size: 32rpx;
					color: #FFFFFF;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					/* 显示省略号 */
				}

				.time {
					line-height: 52rpx;
					height: 52rpx;
					font-size: 26rpx;
					color: #FF2CDF;
				}

				.main_from_top_one_text {
					width: 130rpx;
					text-align: right;
					font-size: 26rpx;
					color: #A6A5AF;
					line-height: 26rpx;
					margin-left: 60rpx;
				}
			}

			.main_from_top_two {
				width: 420rpx;
				position: absolute;
				top: 86rpx;
				left: 192rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.text {
					width: 280rpx;
					height: 52rpx;
					line-height: 52rpx;

					font-weight: 400;
					font-size: 24rpx;
					color: #A6A5AF;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					/* 显示省略号 */
				}

				.num {

					font-size: 30rpx;
					color: #A7A4AD;
				}
			}

			.main_from_top_three {
				width: 420rpx;
				position: absolute;
				top: 146rpx;
				left: 192rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;

				.tag_wrap {
					width: 300rpx;

					font-weight: 400;
					font-size: 24rpx;
					color: #A6A5AF;
					white-space: nowrap;
					/* 不换行 */
					overflow: hidden;
					/* 超出部分隐藏 */
					text-overflow: ellipsis;
					display: flex;

					/* 显示省略号 */
					.tag {
						width: 64rpx;
						height: 36rpx;
						background: linear-gradient(274deg, #0014FF 0%, #8020EF 50%, #FF2CDF 100%);
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						font-size: 22rpx;
						color: #FFFFFF;
						text-align: center;
						line-height: 36rpx;
					}

					.tag_num {
						width: 150rpx;
						height: 36rpx;
						background: #2B2951;
						border-radius: 6rpx 6rpx 6rpx 6rpx;
						text-align: center;
						line-height: 36rpx;
						font-size: 24rpx;
						color: #FFFFFF;
					}
				}

				.price {
					display: flex;
					align-items: center;

					>image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 6rpx;
					}

					font-size: 32rpx;
					color: #FFFFFF;
				}
			}


			.tip {
				position: absolute;
				top: 74rpx;
				right: 0rpx;
				font-size: 36rpx;
				color: #FF2CDF;
			}
		}

		.main_from_bottom {
			width: 630rpx;
			height: 100rpx;
			margin: 0 auto;
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: relative;
			.main_from_bottom_text {
				width: 104rpx;
				height: 52rpx;
				font-size: 26rpx;
				color: #A6A5AF;
				line-height: 52rpx;
			}

			.btn_canel {
				position: absolute;
				right: 30rpx;
				width: 152rpx;
				height: 52rpx;
				border-radius: 536rpx 536rpx 536rpx 536rpx;
				border: 2rpx solid #A6A5AF;
				font-weight: 400;
				font-size: 26rpx;
				color: #A6A5AF;
				line-height: 52rpx;
				text-align: center;
				// margin-left: 226rpx;
			}

			.btn {
				width: 122rpx;
				height: 52rpx;
				border-radius: 536rpx 536rpx 536rpx 536rpx;
				border: 2rpx solid #FF2CDF;
				font-weight: 400;
				font-size: 26rpx;
				color: #FF2CDF;
				line-height: 52rpx;
				text-align: center;
			}
		}
	}

	.prompt {
		width: 600rpx;
		min-height: 400rpx;
		background: #2A2753;
		margin: 0 auto;
		border-radius: 20rpx;
		color: #ffffff;
		padding-top: 30rpx;
	}

	.prompt>text {
		margin-top: 40rpx;
	}

	.prompt_tit {
		margin: 0 30rpx;
		font-size: 28rpx;
		color: #A6A5AF;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}

	.prompt_ntm {
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		width: 414rpx;
		height: 72rpx;
		line-height: 72rpx;
		background: linear-gradient(274deg, #0014FF 0%, #8020EF 50%, #FF2CDF 100%);
		border-radius: 28rpx;
		margin-top: 80rpx;
	}
</style>